from django.http import HttpResponse
from django.shortcuts import render
from links.models import Links

def search_form(request):
    #return render(request, "hello")
    f = open("search/search_form.html")
    return HttpResponse(f)

def search(request):
    if 'q' in request.GET:
        message = "<table>"
        links = Links.objects.filter(content__contains=request.GET['q']).order_by("rank")[:10]
        for link in links:
            message += "<tr><th>%s</th></tr><tr><th>%s</th></tr>" % (link.url, link.content)
    else:
        message = "You submited an empty form"
    message += "</table>"
    return HttpResponse(message)
